import { PluginOption } from 'vite'
import vue from '@vitejs/plugin-vue'
import UnoCSS from 'unocss/vite'
import viteMock from './plugins/mock'
import initAutoImport from './plugins/auto-import'
import initComponents from './plugins/vue-components'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
import initIcons from './plugins/import-icons'
import initSvgIcons from './plugins/svg-icon'
import { ViteEjsPlugin } from 'vite-plugin-ejs'
import vueJsx from '@vitejs/plugin-vue-jsx'
/**
 * 初始创建 vite 插件
 * @param viteEnv
 */
export const initVitePlugins = (viteEnv: ImportMetaEnv, isBuild = false): (PluginOption | PluginOption[])[] => {
  const { VITE_APP_TITLE } = viteEnv
  return [
    vue(),
    vueJsx(),
    ViteEjsPlugin({
      title: VITE_APP_TITLE
    }),
    VueSetupExtend(),
    UnoCSS(),
    // mock
    viteMock(viteEnv, isBuild),
    // 自动导入
    initAutoImport(),
    initComponents(),
    initIcons(),
    initSvgIcons(isBuild)
  ]
}
